<!--
 * @Description: 商品主图视频审核
 * @Author: liyujie
 * @Date: 2021/06/16
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/06/16
-->
<template>
    <div
        class="wrapper"
        ref="wrapper"
    >
        <div class="content-wrapper">
            <!-- header -->
            <div class="header">
                <div class="header-title">
                    商品主图视频审核
                </div>
            </div>
            <!-- /header -->
            <!-- 筛选-->
            <div class="filter-view">
                <div class="header-new-box">
                    <el-radio-group
                        v-model="filterData.verify"
                        size="small"
                        @change="getTableData(1)"
                    >
                        <el-radio-button
                            v-for="item in statusList"
                            :key="item.value"
                            :label="item.value"
                        >
                            {{ item.label }}
                        </el-radio-button>
                    </el-radio-group>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        商品信息
                    </p>
                    <el-input
                        placeholder="请输入商品名称/编号"
                        v-model="filterData.keyword"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        店铺名称
                    </p>
                    <el-input
                        placeholder="请输入店铺名称"
                        v-model="filterData.shop_title"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        提交时间
                    </p>
                    <el-date-picker
                        v-model="dateTimeRange"
                        type="datetimerange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']"
                        size="medium"
                        style="width: 360px"
                        value-format="timestamp"
                    />
                </div>
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        class="query-button"
                        @click="getTableData(1)"
                    >
                        查询
                    </el-button>
                    <el-button
                        type="text"
                        @click="handleReset()"
                    >
                        重置
                    </el-button>
                </div>
            </div>
            <!--筛选-->
            <!-- table -->
            <div class="table-wrapper">
                <el-table
                    :data="tableData"
                    height="100%"
                    style="width: 100%;"
                    ref="table"
                    class="data-table"
                    :cell-style="{height: '123px'}"
                    v-loading="tableLoading"
                >
                    <el-table-column
                        label="序号"
                        align="center"
                        width="80"
                        type="index"
                    />
                    <el-table-column
                        label="商品主图视频"
                        align="center"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <div
                                class="video-wrapper"
                                :style="{background: `url(${scope.row.video_cover}) center center no-repeat`, backgroundSize: 'cover'}"
                                @click="previewVideo(scope.row)"
                            >
                                <img
                                    src="@/assets/image/play.png"
                                    class="video-action"
                                >
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="视频封面"
                        align="center"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <img
                                :src="scope.row.video_cover"
                                class="video-cover"
                                v-if="scope.row.video_cover"
                                @click="fnShowPreview(scope.row.video_cover)"
                            >
                            <div v-else>--</div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="shop_title"
                        label="店铺名称"
                        show-overflow-tooltip
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        width="340"
                        label="商品信息"
                    >
                        <template slot-scope="scope">
                            <div class="goods-info">
                                <img
                                    :src="scope.row.goods_cover"
                                    class="goods-cover"
                                    @click="fnShowPreview(scope.row.goods_cover)"
                                >
                                <div class="info">
                                    <div class="goods-info__title">
                                        {{ scope.row.goods_title }}
                                    </div>
                                    <div class="goods-info__no">
                                        商品ID：{{ scope.row.goods_no }}
                                    </div>
                                </div>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="提交时间"
                        align="left"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.submit_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="审核状态"
                        align="center"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <div class="status-wrapper">
                                <div
                                    :class="['status-dot', scope.row.verify === 0 ? 'warning' : scope.row.verify === -1 ? 'danger' : scope.row.verify === 1 ? 'success' : 'normal']"/>
                                {{ scope.row.verify | statusFilter }}
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="操作"
                        align="left"
                        width="210"
                        fixed="right"
                    >
                        <template slot-scope="scope">
                            <div class="option-btn-group">
                                <el-button
                                    type="text"
                                    size="medium"
                                    v-if="scope.row.verify === 0 || scope.row.verify === -1"
                                    @click="showPassDialog(scope.row)"
                                >
                                    通过
                                </el-button>
                                <el-button
                                    type="text"
                                    size="medium"
                                    v-if="scope.row.verify === 0"
                                    @click="showRejectDialog(scope.row)"
                                >
                                    不通过
                                </el-button>
                                <el-button
                                    type="text"
                                    size="medium"
                                    v-if="scope.row.verify === 1"
                                    @click="showRejectDialog(scope.row)"
                                >
                                    驳回
                                </el-button>
                                <el-button
                                    type="text"
                                    v-if="scope.row.verify === -1"
                                    @click="showRejectDialog(scope.row, 1)"
                                >
                                    驳回原因
                                </el-button>
                                <el-button
                                    type="text"
                                    size="medium"
                                    @click="showLogHistory(scope.row)"
                                >
                                    操作记录
                                </el-button>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <!-- /table -->
            <!-- /分页 -->
            <div class="pagination-wrapper clearfix">
                <el-pagination
                    layout="total, prev, pager, next, jumper"
                    background
                    :current-page.sync="page.now_page"
                    :total="page.total_count"
                    :page-size="page.page_size"
                    @current-change="getTableData"
                />
            </div>
        </div>
        <el-dialog
            title="操作记录"
            :visible.sync="logDialog"
            width="556px"
            :close-on-click-modal="false"
        >
            <div class="log-wrapper">
                <div
                    class="log-list"
                    v-if="logList.length"
                >
                    <div
                        class="log-item"
                        v-for="item in logList"
                        :key="item.id"
                    >
                        <div class="log-item__time">
                            {{ item.log_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                        </div>
                        <div class="log-item__desc">
                            {{ item.type | typeFilter }}
                        </div>
                        <!--<div class="log-item__status">
                            审核状态：
                            <span
                                :class="item.status === 0 ? 'warning' : item.status === 1 ? 'success' : item.status === -1 ? 'error' : 'normal'"
                                :style="{color: index ? '#999' : ''}"
                            >
                                {{ item.status | statusFilter }}
                            </span>
                        </div>-->
                    </div>
                </div>
                <div
                    class="footer"
                    @click="logDialog = false"
                >
                    返回
                </div>
            </div>
        </el-dialog>
        <!-- 驳回弹窗 -->
        <reject-dialog
            ref="rejectDialog"
            :visible.sync="rejectDialog"
            :reason-detail="reasonDetail"
            :maxlength="100"
            @confirm="handleVerify(id,-1, $event)"
        />
        <!-- 图片预览 -->
        <img-preview ref="preview"/>
        <!-- 视频播放组件 -->
        <video-simple
            ref="videoSimple"
            :url="video_cover"
            :top="54"
            :left="left"
        />
    </div>
</template>

<script>
import { back } from '@/mixin/back';
import ImgPreview from "@/components/common/img-preview";
import RejectDialog from "@/components/dialog/reject-dialog";
import VideoSimple from "@/components/dorm/video-simple";

export default {
    name: 'GoodsVideoVerify',
    mixins: [back],
    components: {VideoSimple, RejectDialog, ImgPreview},
    data() {
        return {
            filterData: {
                keyword: '',
                shop_title: '',
                verify: 99,
                start_time: '',
                end_time: ''
            },
            tableData: [],
            tableLoading: false,
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
            dateTimeRange: [],
            statusList: [
                {label: '全部', value: 99},
                {label: '待审核', value: 0},
                {label: '已通过', value: 1},
                {label: '未通过', value: -1},
            ],
            id: '',
            reasonDetail: '',
            rejectDialog: false,
            logDialog: false,
            logList: [],
            video_cover: '',
            left: 0,
            authResult: {}
        };
    },
    computed: {},
    watch: {
        dateTimeRange(value) {
            this.filterData.start_time = value ? value[0] / 1000 : '';
            this.filterData.end_time = value ? value[1] / 1000 : '';
            this.getTableData(1);
        }
    },
    filters: {
        statusFilter(val) {
            switch (val) {
                case 0:
                    return '待审核';
                case 1:
                    return '已通过';
                case -1:
                    return '未通过';
                default:
                    return '无';
            }
        },
        typeFilter(val) {
            switch (val) {
                case 1:
                    return '首次提交商品主图视频';
                case 2:
                    return '更新视频地址';
                case 4:
                    return '更新商品主图视频封面';
                case 8:
                    return '删除商品主图视频和视频封面';
                case 16:
                    return '提交了新的商品主图视频和视频封面';
                case 24:
                    return '删除并提交了新的商品主图视频和视频封面';
                case 32:
                    return '平台审核通过';
                case 64:
                    return '平台审核不通过';
                default:
                    return '--';
            }
        }
    },
    mounted() {
        this.$store.commit('SET_HEADER', [{title: "APP后台"}, {title: '商城'}, {title: '商品主图视频审核'}]);
        this.authResult = this.$route.meta.authResult;
        this.getTableData();
    },

    methods: {
        /**
         * @description 获取列表数据
         * @param page
         */
        getTableData(page) {
            this.tableLoading = true;
            let params = { ...this.filterData };

            params.page_id = page || this.page.now_page;
            this.$post('/student/shop_goods%5Ccover_video_audit_list', params, res => {
                if (res.code === 1) {
                    this.tableData = res.data.list;
                    this.page = res.data.page;
                } else {
                    this.$notify({
                        title: '提示',
                        message: res.msg,
                        type: 'warning'
                    });
                }
                this.tableLoading = false;
            });
        },

        /**
         * 路由跳转
         * @param routeName
         * @param query
         */
        handleRoute(routeName, query) {
            this.$router.push({
                name: routeName,
                query
            });
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        },

        /**
         * 重置筛选条件
         */
        handleReset() {
            this.filterData = {
                keyword: '',
                shop_title: '',
                verify: 99,
                start_time: '',
                end_time: ''
            };
            this.dateTimeRange = null;
            this.getTableData(1);
        },

        /**
         * 预览图片
         * @param   {String}    images      //单图预览
         * @param   {Array}     images      //多图预览
         * @param index
         */
        fnShowPreview(images, index) {
            if (images && Object.prototype.toString.call(images) == '[object String]') {
                this.$refs.preview.show([
                    images
                ]);
            } else if (images && Object.prototype.toString.call(images) == '[object Array]') {
                this.$refs.preview.show(images, index);
            } else {
                this.$message({
                    type: 'warning',
                    message: '图片类型错误'
                });
            }
        },

        /**
         * 审核通过提示弹窗
         * @param row
         */
        showPassDialog(row) {
            if(!this.authResult.auth_verify) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }
            this.$zdConfirm('是否确认通过该主图视频的审核？', '审核通过提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.handleVerify(row.id, 1);
            }).catch(() => {});
        },

        /**
         * 驳回弹窗
         * @param type - 0填写驳回原因  1回显原因
         * @param row
         */
        showRejectDialog(row, type = 0) {
            if(type === 1) {
                // 回显
                this.reasonDetail = row.verify_reason;
                this.rejectDialog = true;
            } else {
                if(!this.authResult.auth_verify) {
                    this.$notify({
                        title: '提示',
                        message: '请联系管理员添加权限',
                        type: 'warning',
                        duration: 2000
                    });
                    return false;
                }
                // 填写
                this.id = row.id;
                this.$refs.rejectDialog.reason = '视频内容含敏感信息、危害信息';
                this.reasonDetail = '';
                this.rejectDialog = true;
            }
        },

        /**
         * 审核
         * @param verify - 1通过  -1拒绝
         * @param id - 编号
         * @param verify_reason - 拒绝原因
         */
        handleVerify(id, verify, verify_reason = '') {
            let params = {
                id,
                verify_reason,
                verify
            };

            this.$post('/student/shop_goods%5Ccover_video_audit', params, resp => {
                if (resp.code === 1) {
                    this.rejectDialog = false;
                    this.getTableData();
                    this.$notify({
                        title: '成功',
                        message: '操作成功',
                        duration: 2000,
                        type: 'success'
                    });
                } else {
                    this.$notify({
                        title: '提示',
                        message: resp.msg,
                        duration: 2000,
                        type: 'warning'
                    });
                }
            });
        },

        /**
         * 预览视频
         * @param row
         */
        previewVideo(row) {
            this.video_cover = row.video_url;
            this.left = this.$refs.wrapper.clientWidth - 300;
            this.$refs.videoSimple.showVideo();
        },

        /**
         * 显示操作记录弹窗
         * @param row
         */
        showLogHistory(row) {
            if(!this.authResult.auth_log) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }
            let params = {
                goods_no: row.goods_no
            };

            this.$post('/student/shop_goods%5Ccover_video_log_list', params, resp => {
                if (resp.code === 1) {
                    this.logList = resp.data.list;
                    this.logDialog = true;
                } else {
                    this.$notify({
                        title: '提示',
                        message: resp.msg,
                        duration: 2000,
                        type: 'warning'
                    });
                }
            });
        }
    }
};
</script>

<style lang="less" scoped>
.wrapper {
    width: 100%;

    .content-wrapper {
        display: flex;
        height: calc(100% - 24px);
        flex-direction: column;
        position: relative;
        margin: 12px;
        background: #fff;
        box-sizing: border-box;

        /*header*/

        .header {
            height: 68px;
            padding: 24px;
            box-sizing: border-box;
            box-shadow: 0px -1px 0px 0px #F0F2F5;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid #F0F2F5;

            .header-title {
                color: #333333;
                font-size: 20px;
                height: 20px;
                font-weight: 500;
                position: relative;
                margin: 24px 0 24px 12px;

                &::before {
                    content: '';
                    position: absolute;
                    left: -8px;
                    top: -1px;
                    width: 3px;
                    height: 20px;
                    background: #1890FF;
                }
            }
        }

        /*筛选*/

        .filter-view {
            box-sizing: border-box;
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            padding: 0 24px;
            margin-top: 12px;

            .header-new-box {
                display: flex;
                align-items: center;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #333333;
                white-space: nowrap;
                margin-right: 24px;
                margin-bottom: 12px;

                &-title {
                    margin-right: 16px;
                    white-space: nowrap;
                }
                .query-button  {
                    width: 84px;
                    height: 36px;
                    background: #FFFFFF;
                    border-radius: 4px;
                    border: 1px solid #1890FF;
                    font-size: 14px;
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    color: #1890FF;
                    margin-right: 12px;
                }
            }
        }

        // 表格
        .table-wrapper {
            padding: 0 24px;
            flex: 1;
            height: 0;
            .task-info {
                display: flex;
                align-items: center;
                font-size: 14px;
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: #333333;
                line-height: 20px;
                /deep/ .el-image {
                    flex-shrink: 0;
                    img {
                        width: 50px;
                        height: 50px;
                    }
                }
                .task-title {
                    display: -webkit-box;
                    -webkit-box-orient: vertical;
                    overflow: hidden;
                    -webkit-line-clamp: 2;
                }
            }
        }
        .video-cover {
            width: 90px;
            height: 90px;
            object-fit: cover;
            cursor: pointer;
        }
        .video-wrapper {
            position: relative;
            cursor: pointer;
            width: 90px;
            height: 90px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-left: 50%;
            transform: translateX(-50%);
            .video-action {
                width: 34px;
                position: absolute;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
                pointer-events: none;
            }
        }
        .goods-info {
            display: flex;
            align-items: center;
            .goods-cover {
                width: 90px;
                height: 90px;
                cursor: pointer;
                margin-right: 16px;
                flex-shrink: 0;
            }
            .info {
                display: flex;
                flex-direction: column;
                justify-content: space-between;
                font-size: 12px;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #333333;
                height: 90px;
                .goods-info__title {
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #333333;
                    font-size: 14px;
                    display: -webkit-box;
                    -webkit-box-orient: vertical;
                    overflow: hidden;
                    -webkit-line-clamp: 2;
                    margin-bottom: 8px;
                }
                .goods-info__no {
                    font-size: 14px;
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #333333;
                }
            }
        }

        .status-wrapper {
            display: flex;
            align-items: center;
            justify-content: center;

            .status-dot {
                width: 6px;
                height: 6px;
                border-radius: 50%;
                margin-right: 5px;

                &.success {
                    background: #4CD964;
                }

                &.danger {
                    background: #FF3030;
                }

                &.warning {
                    background: #FFA72D;
                }

                &.normal {
                    background: #A6A6A6;
                }
            }
        }

        /* 分页 */
        .pagination-wrapper {
            padding: 12px 24px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    .log-wrapper {
        .log-list {
            padding: 38px 53px 10px;
            max-height: 400px;
            overflow-y: auto;
            &::-webkit-scrollbar {
                width: 6px;
            }
            .log-item {
                margin-bottom: 28px;
                font-size: 14px;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #333333;
                display: flex;
                align-items: center;
                &__time, &__desc {
                    margin-right: 20px;
                }
                &__status {
                    .success {
                        color: #2FBDB3;
                    }
                    .warning {
                        color: #F79038;
                    }
                    .error {
                        color: #F95B56;
                    }
                    .normal {
                        color: #999999;
                    }
                }
            }
        }
        .footer {
            height: 52px;
            background: #FFFFFF;
            border-radius: 0 0 4px 4px;
            border-top: 1px solid #E9E9E9;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 16px;
            font-family: PingFangSC-Medium, PingFang SC;
            font-weight: 500;
            color: #333333;
            cursor: pointer;
        }
    }
    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow:0 1px 0 0 rgba(233,233,233,1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;
        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }
        .el-icon-close:before {
            color: rgb(194,194,194);
            font-size: 17px;
            font-weight: bold;
        }
        .el-dialog__headerbtn {
            top: 14px;
        }
    }
    /deep/ .el-dialog__body {
        padding: 0;
    }
    /deep/ .el-textarea__inner {
        resize: none;
    }
    /deep/ .el-table__fixed-right {
        right: 6px!important;
    }
    .data-table {
        ::-webkit-scrollbar {
            width: 6px;
            height: 6px;
        }
        // 操作按钮
        .option-btn-group {
            .el-button {
                margin-left: 0;
                margin-right: 10px;
            }
        }
    }
    /deep/ .el-radio-button {
        &.is-active {
            .el-radio-button__inner {
                background: #E6F1FC;
                color: #20A0FF;
                border-color: #20A0FF;
            }
        }
    }
}
</style>
